package com.niren.relay.redis.formatjson;

import com.alibaba.fastjson.JSON;
import com.niren.relay.common.constant.constant;
import com.niren.relay.redis.RedisInterface;
import com.niren.relay.redis.RedisString;
import com.sun.org.apache.xpath.internal.operations.Bool;

import java.util.HashSet;


public class String2Json<T> {
    private RedisInterface rstring = new RedisString(constant.hostOrIp);

    public Boolean Class2Json(String key,T t){
        String jsonStr = JSON.toJSONString(t);
        System.out.println("更新的信息：" + jsonStr);
        rstring.setValue(key, jsonStr);
        return true;
    }

    public T Json2Class(String key,Class<T> clazz){
        return (T) JSON.parseObject(rstring.getValue(key),clazz);
    }

    public Boolean DelJsonString(String key){
        return rstring.delValue(key);
    }

    public HashSet<String> getKeys(String rule){
        return rstring.getKeys(rule);
    }
}
